﻿#pragma once

#include "df_macro.h"

namespace df
{

	class WarpExpand
	{
	public:
		template<class T>
		static void Construct(T *)
		{

		}

		template<class T>
		static void Destruct(T *)
		{

		}
	};


	template<class T, class _Expand = WarpExpand>
	class PtrWrap
	{
	public:
		PtrWrap(T & er)
		{
			objPtr_ = &er;
			_Expand::Construct(objPtr_);
		}

		PtrWrap(const PtrWrap & er)
		{
			objPtr_ = er.objPtr_;
		}

		PtrWrap(T * er)
		{
			objPtr_ = er;
			_Expand::Construct(objPtr_);
		}

		~PtrWrap()
		{
			_Expand::Destruct(objPtr_);
		}

		inline operator bool() const
		{
			return objPtr_ != nullptr;
		}


		inline bool operator== (T * obj)
		{
			return objPtr_ == obj;
		}

		inline bool operator!= (T * obj)
		{
			return objPtr_ != obj;
		}

		inline T * Get() const
		{
			return objPtr_;
		}

		inline T * get() const
		{
			return objPtr_;
		}

		//取对象指针
		inline T * operator->() const
		{
			DF_ASSERT(objPtr_ != nullptr);
			return objPtr_;
		}

		//取对象指针
		inline T & operator*()
		{
			DF_ASSERT(objPtr_ != nullptr);
			return *objPtr_;
		}

		T * objPtr_ = nullptr;

		//DF_DISABLE_COPY_ASSIGN(PtrWarp);
	};

}
